package xyz.ddlnt.serviceusr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import xyz.ddlnt.commonutil.util.RandomUtil;
import xyz.ddlnt.model.dto.PostCommentAreaDTO;
import xyz.ddlnt.model.dto.PostCommentDTO;
import xyz.ddlnt.model.entity.PostComment;
import xyz.ddlnt.model.vo.MyCommentVO;
import xyz.ddlnt.model.vo.PostCommentVO;
import xyz.ddlnt.model.vo.ReplyCommentVO;
import xyz.ddlnt.serviceusr.mapper.PostCommentMapper;
import xyz.ddlnt.serviceusr.service.PostCommentService;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/25 14:18
 */
@Slf4j
@Service
public class PostCommentServiceImpl extends ServiceImpl<PostCommentMapper, PostComment> implements PostCommentService {
    @Resource
    private PostCommentMapper postCommentMapper;


    @Override
    public Boolean savePostComment(PostCommentDTO postCommentDTO) {
        PostComment postComment = PostComment.builder()
                .id(RandomUtil.generate12DigitRandomNumber())
                .postId(postCommentDTO.getPostId())
                .layerAreaId(postCommentDTO.getLayerAreaId())
                .replyToUserId(postCommentDTO.getReplyToUserId())
                .userId(postCommentDTO.getUserId())
                .commentContent(postCommentDTO.getCommentContent())
                .commentTime(LocalDateTime.now())
                .build();
        return postCommentMapper.insert(postComment) == 1;
    }

    @Override
    public List<PostCommentVO> getPostComment(PostCommentAreaDTO postCommentAreaDTO) {
        IPage<PostCommentVO> page = new Page<>(postCommentAreaDTO.getPageDTO().getPageNum(), postCommentAreaDTO.getPageDTO().getPageSize());
        return postCommentMapper.selectComment(page, postCommentAreaDTO);
    }

    @Override
    public List<MyCommentVO> getMyComment(Long id) {
        return postCommentMapper.selectMyComment(id);
    }

    @Override
    public List<ReplyCommentVO> getReplyComment(Long id) {
        return postCommentMapper.selectReplyComment(id);
    }


}
